{% extends 'ShopAdminBundle::base.html.twig' %}
{% block plugin_css %}
    <link href="{{ asset('css/login.css') }}" rel="stylesheet">
{% endblock %}

{% block main_content %}
<div class="container">
    <div class="row">
        <div class="col-md-4 col-md-offset-4">
            <div class="login-panel panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title">后台用户登录</h3>
                </div>
                <div class="panel-body">

                    <form role="form" action="{{ path('admin_login_handle') }}" method="post">
                        <fieldset>
                            <div class="form-group">
                                <input class="form-control" placeholder="用户名" name="username" id="username" type="text" autofocus>
                            </div>
                            <div class="form-group">
                                <input class="form-control" placeholder="密码" name="password" id="password" type="password" value="">
                            </div>

                            <div class="checkbox">
                                <label>
                                    <input name="remember" type="checkbox">下次自动登录
                                </label>
                            </div>

                            <input type="button" id="btn-login" class="btn btn-lg btn-success btn-block" value="登录">
                        </fieldset>
                    </form>

                </div>
            </div>
        </div>
    </div>
</div>

{% endblock %}


{% block plugin_js %}
<script>
  var btn_login=$('#btn-login');
    btn_login.on('click', function(){
        var fm=$(this).parents('form'),
                fm_data=fm.serialize(),
                fm_obj=wxi.string.qs2obj(fm_data);

        if(!fm_obj.username){
            wxi.util.tipMsg('','请填写用户名');
            return false;
        }
        if(!fm_obj.password){
            wxi.util.tipMsg('','请填写密码');
            return false;
        }

        $.post('/admin/handle_login',
                {username:fm_obj.username, password:fm_obj.password},
                function(d){
                    if(d.success==true){
                        wxi.util.tipMsg('', '登录成功', 1000, function(){
                           redirect('/admin/brand');
                        });
                    }
                    else{
                        wxi.util.tipMsg('', '用户名或密码错误');
                        return false;
                    }

        },'json');

    });

    $('#username, #password').on('focus', function(){
       $('body').on('keydown', function(e){
           if(e.which == 13){
               btn_login.trigger('click');
               return false;
           }
       });
    });


</script>
{% endblock %}


